package org.lemon.transport.context.service;

import org.lemon.transport.context.auth.GetOrCreateDeviceFromGatewayResponse;
import org.lemon.transport.context.auth.ValidateDeviceCredentialsResponse;
import org.lemon.transport.context.data.device.DeviceTransportType;
import org.lemon.transport.context.model.SessionMetaData;
import org.lemon.transport.context.session.SessionMsgListener;
import org.server.transport.gen.SessionProto;
import org.server.transport.gen.TransportApiProto;
import org.server.transport.gen.TransportProto;
import org.server.transport.gen.TransportProto;

import java.util.List;
import java.util.concurrent.Executor;

public interface TransportService {

    Executor getCallbackExecutor();

    List<TransportProto.GetQueueRoutingInfoResponseMsg> getQueueRoutingInfo(TransportProto.GetAllQueueRoutingInfoRequestMsg msg);

    /**
     * 设备accessToken 验证
     *
     * @param transportType
     * @param token
     * @param responseCallback
     */
    void deviceTokenValidate(DeviceTransportType transportType, String token,
                             TransportAuthServiceCallback<ValidateDeviceCredentialsResponse> responseCallback);

    /**
     * mqtt 账号密码连接验证
     *
     * @param transportType
     * @param clientId
     * @param username
     * @param password
     * @param responseCallback
     */
    void basicMqttCredValidate(DeviceTransportType transportType, String clientId, String username, String password,
                               TransportAuthServiceCallback<ValidateDeviceCredentialsResponse> responseCallback);

    /**
     * 设备x509 证书验证
     *
     * @param transportType
     * @param certHash
     * @param responseCallback
     */
    void deviceX509CertValidate(DeviceTransportType transportType, String certHash,
                                TransportAuthServiceCallback<ValidateDeviceCredentialsResponse> responseCallback);


    void process(TransportApiProto.GetOrCreateDeviceFromGatewayRequestMsg msg,
                 TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse> callback);

    /**
     * 处理设备连接session事件消息
     *
     * @param sessionInfo
     * @param msg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, SessionProto.SessionEventMsg msg,
                 TransportServiceCallback<Void> callback);

    /**
     * 设备遥测数据上报处理
     *
     * @param sessionInfo
     * @param msg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.PostTelemetryMsg msg,
                 TransportServiceCallback<Void> callback);

    /**
     * 设备属性数据上报处理
     *
     * @param sessionInfo
     * @param msg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.PostAttributeMsg msg,
                 TransportServiceCallback<Void> callback);

    /**
     * 获取设备属性值
     *
     * @param session
     * @param requestMsg
     * @param getAttributeResponseMsgTransportServiceCallback
     */
    void process(SessionProto.SessionInfoProto session, TransportProto.GetAttributeRequestMsg requestMsg,
                 TransportServiceCallback<TransportProto.GetAttributeResponseMsg> getAttributeResponseMsgTransportServiceCallback);

    /**
     * @param requestMsg
     * @param callback
     */
    void process(TransportProto.ProvisionDeviceRequestMsg requestMsg,
                 TransportServiceCallback<TransportProto.ProvisionDeviceResponseMsg> callback);

    /**
     * 处理获取设备固件/软件Ota包信息
     *
     * @param sessionInfoProto
     * @param requestMsg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfoProto,
                 TransportProto.GetOtaPackageRequestMsg requestMsg, TransportServiceCallback<TransportProto.GetOtaPackageResponseMsg> callback);

    /**
     * 设备订阅RPC消息
     *
     * @param sessionInfo
     * @param msg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.SubscribeToRPCMsg msg,
                 TransportServiceCallback<Void> callback);

    /**
     * 设备订阅属性更新消息
     *
     * @param sessionInfo
     * @param msg
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.SubscribeToAttributeUpdatesMsg msg,
                 TransportServiceCallback<Void> callback);

    /**
     * 处理订阅信息
     *
     * @param sessionInfo
     * @param subscriptionInfo
     * @param callback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.SubscriptionInfoProto subscriptionInfo, TransportServiceCallback<TransportProto.GetAttributeResponseMsg> callback);

    /**
     *
     * @param msg
     * @param callback
     */
    void process(TransportProto.TransportToDeviceActorMsg msg, TransportServiceCallback<Void> callback);

    /**
     * 设备认领
     * @param sessionInfo
     * @param claimDeviceMsg
     * @param pubAckCallback
     */
    void process(SessionProto.SessionInfoProto sessionInfo, TransportProto.ClaimDeviceMsg claimDeviceMsg, TransportServiceCallback<Void> pubAckCallback);

    /**
     * 取消设备登录session的注册
     *
     * @param session
     */
    void deregisterSession(SessionProto.SessionInfoProto session);

    /**
     * 处理日志信息
     *
     * @param session
     * @param message
     */
    void log(SessionProto.SessionInfoProto session, String message);

    SessionMetaData registerSyncSession(SessionProto.SessionInfoProto sessionInfo, SessionMsgListener listener, long timeout);

    SessionMetaData registerAsyncSession(SessionProto.SessionInfoProto session, SessionMsgListener listener);

    void reportActivity(SessionProto.SessionInfoProto sessionInfo);

}
